package second.binarytree;


public class Solution23 {
    TreeNode pre = null;

    public boolean isValidBST(TreeNode root) {
        if (root == null) return true;
        boolean left = isValidBST(root.left);

        if (pre != null) {
            if (pre.val >= root.val) return false;
        }
        pre = root;

        boolean right = isValidBST(root.right);
        return right && left;
    }
}

